﻿using System.IO;
using ProphetsWay.myMd5.Core;
using ProphetsWay.myMedia.DataAccess.Core;
using ProphetsWay.Utilities;

namespace ProphetsWay.myMedia.Core.Entities
{
	public class ProtoMedia
	{
		private readonly FileInfo _fileInfo;

		public ProtoMedia(string mediaUri) { _fileInfo = new FileInfo(mediaUri); }

		public string Uri { get { return _fileInfo.FullName; } }

		public string FileName { get { return _fileInfo.Name; } }

		public FileInfo File { get { return _fileInfo; } }

		private bool _extFound;
		private FileTypes _ext;
		public FileTypes Extension
		{
			get
			{
				if (!_extFound)
				{
					_ext = _fileInfo.Extension.Replace(".", "").GetValue<FileTypes>();
					_extFound = true;
				}

				return _ext;
			}
		}

		private string _md5;
		public string Md5
		{
			get
			{
				if (string.IsNullOrEmpty(_md5))
					RegenerateMd5();

				return _md5;
			}
		}

		public void RegenerateMd5()
		{
			_md5 = _fileInfo.GenerateMd5();
		}
	}
}
